package com.google.code.yargon.engine;

import java.util.ArrayList;

import com.google.code.yargon.engine.Item.typeOfItem;

/**
 * @author Tuomas Oinonen
 */

public class ItemStack extends ItemPile {

	/**
	 * Constructor, sets stacks type to CONTAINER as default
	 */

	public ItemStack() {
		this.setType(Item.typeOfItem.CONTAINER);
	}

	/**
	 * Add item to stack as an {@link Item}
	 * 
	 * @param newItem
	 */

	public void addToStack(Item newItem) {
		String typeOfItem = newItem.getType().toString();
		/* If itempile exists */
		if (getItemPile().containsKey(typeOfItem)) {
			addToExistingPile(this, newItem);
			/* Create new pile */
		} else {
			addToNewPile(this, newItem);
		}
	}

	/**
	 * Fetch item
	 * 
	 * @param newItem
	 * @return {@link Item}
	 */

	public Item getItem(Item newItem) {
		return getItemByItem(this, newItem);
	}

	/**
	 * Fetch item by name
	 * 
	 * @param newItem
	 * @return {@link Item}
	 */

	public Item getByName(String newItem) {
		return getItemByName(this, newItem);
	}

	/**
	 * Fetch arraylist of items by type
	 * 
	 * @param ItemType
	 * @return
	 */

	public ArrayList<Item> getByType(typeOfItem ItemType) {
		return getItemByType(this, ItemType);
	}

	/**
	 * Change item from stack to stack
	 * 
	 * @param item
	 * @param toStack
	 */

	public void changeStack(Item item, ItemStack toStack) {
		changeItemStack(this, toStack, item);
	}
	
	/**
	 * Change items from stack to stack by type
	 * 
	 * @param toStack
	 * @param ItemType
	 */

	public void changeByType(ItemPile toStack, typeOfItem ItemType) {
		changeStackByType(this, toStack, ItemType);
	}

	/**
	 * Remove item from stack
	 * 
	 * @param item
	 */

	public void removeItem(Item item) {
		removeStackItem(this, item);
	}

	/**
	 * Remove items from stack by type
	 * 
	 * @param ItemType
	 */

	public void removeType(typeOfItem ItemType) {
		removeStackByType(this, ItemType);
	}

	/**
	 * List all stack items inc. subclass
	 */

	public void listItems() {
		listByStack(this);
	}
	
	/**
	 * List stack items
	 */
	
	public void listStack() {
		listByPile(this);
	}

}
